<template>
	<view>
		
		<goodsList :goodsList='sortGoodList' :hasPolishedId='hasPolishedId'></goodsList>
		
		<!-- <soldOutList :soldOutList='soldOutList'></soldOutList> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				Booklist:[],
				classifyId1:0,
				sortGoodList:[],
				hasPolishedId:[],
				goodsList:[],
				soldOutList:[],
				timeList:[],
				header:'',
				current:0,
				tabslist: [{name:'闲置物品'},{name:'二手教材'}],
			}
		},
		computed:{
		},
		onLoad(){
			let header = new Object()
			header.Authority = getApp().globalData.header.Authority
			this.header = header
			console.log('onload-----------------------')
			uni.showLoading({
				title: '加载中'
			})
		},
		async onShow(){
			console.log('onShow------------------');
			this.getGoodsList();
			this.getSoldOutGoods()
		},
			methods: {
				tabsChange(index){
					console.log('tabs改变了',index)
					this.current =index
				},
				async getSoldOutGoods(){
					let header = new Object
					header.Authority = getApp().globalData.Authority
					let res = await getApp().UniRequest(`/twohandbook/goods/authority/mine/history?Authority=${header.Authority}`,'GET','',header)
					console.log('获取已下架商品信息',res)
					if(res.code==20000){
						// this.soldOutList=res.data.list;
					}
				},
				async getGoodsList(){
					let res = await getApp().UniRequest('/twohandbook/goods/authority/mine?Authority='+this.header.Authority,'GET','',this.header)
					console.log('获取发布的商品信息',res)
					if(res.code==20000){
						this.goodsList = res.data.list
						console.log('this.goodsList',this.goodsList)
						uni.hideLoading()
					}
					let length = this.goodsList.length;
					// let a = this.goodsList[0].goods.createTime.substr(0,10)
					this.timeList=[]
					for(let i=0;i<length;i++){
						this.timeList.push(this.goodsList[i].goods.createTime.substr(0,10));
					}
					console.log('截取之后的时间',this.timeList)
					this.timeList = [...new Set(this.timeList)];
					console.log('去重之后的timeList',this.timeList)
					this.timeList.reverse()
					let timeLength = this.timeList.length
					this.sortGoodList=[]
					for(let i=0;i<timeLength;i++){
						let arr = this.goodsList.filter(item=>item.goods.createTime.substr(0,10)==this.timeList[i])
						arr.reverse()
						this.sortGoodList.push(arr) 
					}
						console.log('分类之后的this.sortGoodList',this.sortGoodList)
						this.sortGoodList.forEach((item,index)=>{
							item.forEach((item1,index1)=>{
								if(item1.polish==true){
									this.hasPolishedId.push(item1.goods.id)
								}
							})
						})
				}
			}
	}
</script>

<style lang="scss">
	.history{
		margin-top: 28rpx;
	}
	
.u-page {
		&__button-item {
			width: 25%;
			margin: 0 15px 15px 0;
		}
	}
	.bgImg{
		width: 76%;
		margin: 100rpx auto;
		image{
			width: 100%;
			
		}
	}
	.u-safe-area-inset-bottom {
	     padding-bottom: 0; 
	}
		.u-node {
			width: 44rpx;
			height: 44rpx;
			border-radius: 100rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			background: #d0d0d0;
		}
		
		.u-order-title {
			color: #333333;
			font-weight: bold;
			font-size: 32rpx;
		}
		
		.u-order-desc {
			color: rgb(150, 150, 150);
			font-size: 28rpx;
			margin-bottom: 6rpx;
		}
		
		.u-order-time {
			color: rgb(200, 200, 200);
			font-size: 26rpx;
		}
		.timeLine{
			width: 93%;
			margin: 0 auto;
		}
</style>
